package org.vectrics.recruiter.user.resume.email;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

import org.apache.log4j.Logger;
import org.vectrics.domain.Domain;
import org.vectrics.recruiter.RecruitServiceLocator;
import org.vectrics.recruiter.job.Job;
import org.vectrics.recruiter.job.JobSearchCriteria;

public class JobExtractor {
	private transient Logger log = Logger.getLogger(this.getClass());

	
	public Set findTestsInText(Domain domain, String text) {
		Set jobList = new HashSet();
		JobSearchCriteria criteria = new JobSearchCriteria();
		criteria.addDomain(domain);
		criteria.getDomains().addAll(domain.retrieveChildrenInBranch());
		
		if (text != null) {
			WordExtractor wordExtractor = RecruitServiceLocator.getWordExtractor();
			WordList wordList = wordExtractor.getWordList(text);
			Iterator iter = wordList.iterator();
			while (iter.hasNext()) {
				Word word = (Word)iter.next();
				if (word.getType().equals(Word.TYPE_WORD)) {
					criteria.addReferenceCode(word.getValue());
				}
			}
		}
		
		if (criteria.getReferenceCodes().size() > 0) {
			jobList.addAll(RecruitServiceLocator.getJobProvider().findJobs(criteria, 0, 100));
		}
		
		return(jobList);
	}
	
	
	
}
